﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace Thallo {
    class CacheProxyCallHandler : ICallHandler, IDisposable {

        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) {
            using (var context = new InvocationContext(input)) {
                //context.MethodBase = input.MethodBase;
                //context.Inputs = input.Inputs.GetValues().ToArray();
                var result = Interceptor.Current.BeforeProcess(input);                
                bool update = false;
                if (result == null) {
                    result = getNext().Invoke(input, getNext);
                    update = true;
                }
                if (result.Exception == null)
                    Interceptor.Current.AfterProcess(input, result, update);
                return result;
            }
        }

        public int Order {
            get;
            set;
        }

        public void Dispose() {
             
        }
    }
}
